#include "BDD.h"


int id =1;


void loadEx1()
{
	graph g1;
	char c;
//	This will load example 1.	
	printf("Loading Example 1.....\n");
	ex1(&g1);
//	deInit(&g1);  Do deInit Some other time
	//pause;
	printf("Example 1 Loaded.....\n");
	printf("Reduce Function.....\n");
	//printf("Reduce Function.....\n");
	reduction(&g1,4);
	//pause;
	printf("------------------------------------------\n");	
	printf("Press Enter to Continue\n");
	scanf("%c",&c);
}


void loadEx2()
{
	//// Loading Example 2
	graph g1,g2, g3;	
	char c;
	printf("Loading Example 2.....\n");
	ex2(&g1,&g2);
	//pause;
	printf("Example 2 Loaded.....\n");
	printf("Apply Function.....\n");
	/*g3 =*/ applyFunc(&g3,&g1, &g2,4,4,'+');
	//pause;
	printf("------------------------------------------\n");	
	printf("Press Enter to Continue\n");
	scanf("%c",&c);
//	reduction(&g1,3);
//	reduction(&g2,3);
	

}

void loadEx3()
{
//////////////// Example 3
	
	graph g1,g2, g3, g4;
	char c;
	printf("Loading Example 3.....\n");
	ex3(&g4);
	//pause;
	printf("Example 3 Loaded.....\n");
	printf("Reduce Function.....\n");
	reduction(&g4,6);
	printf("------------------------------------------\n");	
	printf("Press Enter to Continue\n");
	scanf("%c",&c);




}

void new()
{
	//////// Take values from user
	graph g5;
	g5.totVar = 0;
	char c[3];
	char argv[1000], tempArgv[1000];
	int i= 0;
	for(;i<1000;i++)
		g5.variables[i] = NULL;

	printf("Please Enter Boolean equation:\n");
	scanf("%s", argv);
	strcpy(tempArgv,argv);
	initVariables(tempArgv, g5.variables, &g5);
	build(&g5,tempArgv);

	while(TRUE)
	{
		printf("\n Operation on BDD: \n\
	1: Size of Graph\n\
	2: Reduction\n\
	3: Show Index\n\
	4: Change Index\n\
	b: Go back to main menu\n");
		scanf("%s",c);
		switch(c[0])
		{
			case '1': printf("Total no. of nodes are: %d",graphSize(&g5,(g5.totVar)+1) ) ;break;
			case '2': reduction(&g5,((g5.totVar)+1)); break;
			case '3': showIndex(&g5); break;
			case '4':
				  changeIndex(&g5); 
			 	  strcpy(tempArgv,argv);
				  printf("%s \n", argv);
				  build(&g5,tempArgv);break;
			case 'b': printf("------------------------------------------\n");return ; break;
			default	: printf("Invalid Option\n"); break;
		}
		
	}

}



void newPOBDD()
{

	//////// Take values from user
	graph g5;
	g5.totVar = 0;
	char c[3];
	char argv[1000], tempArgv[1000];
	int i= 0;
	for(;i<1000;i++)
		g5.variables[i] = NULL;

	printf("Please Enter Boolean equation:\n");
	scanf("%s", argv);
	strcpy(tempArgv,argv);
	initVariables(tempArgv, g5.variables,&g5);
	initDecompositionSet(g5.dSet);
	buildPartial(&g5,tempArgv);

	while(TRUE)
	{
		printf("\n Operation on POBDD: \n\
	1: Size of Graph\n\
	2: Show Index\n\
	b: Go back to main menu\n");
		scanf("%s",c);
		switch(c[0])
		{
			case '1': printf("Total no. of nodes are: %d",graphSize(&g5,((g5.totVar)+1) ) );break;
			case '2': showIndex(&g5); /*printf("\nPress any key to continue"); c = getchar();*/ break;
			case 'b': printf("------------------------------------------\n");return ; break;
			default	: printf("Invalid Option\n"); break;
		}
		
	}
}



void main(int argc, char *argv[])
{
	graph g1,g2, g3,g4,g5;
	char c[3];
	while(TRUE)
	{
		printf("\nPlease enter a no:\n \
	1 : To load Ex.1\n\
	2 : To Load Ex.2\n\
	3 : To Load Ex.3\n\
	4 : To create a new OBDD\n\
	5 : To creae a new POBDD\n\
	q : To Exit\n ");
		scanf("%s",c);
		switch(c[0])
		{
			case '1': loadEx1(); break;
			case '2': loadEx2(); break;
			case '3': loadEx3(); break;
			case '4': new(); break;
			case '5': newPOBDD(); break;
			case 'q': return; break;
			default : printf("Invalid option \n"); break;
		}

	}
}

